package com.sec.android.app.myfiles.module.cloud;

import android.content.ClipData;
import android.view.DragEvent;
import android.view.View;
import android.widget.AbsListView;

import com.sec.android.app.myfiles.feature.DragAndDropMgr;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.abstraction.AbsDragAndDrop;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.util.UiUtils;
import com.sec.android.app.myfiles.widget.listview.AbsListViewImp;

import java.util.ArrayList;

/**
 * Created by sev_user on 11/2/2016.
 */
public class CloudDragAndDropImp extends AbsDragAndDrop {

    public CloudDragAndDropImp(AbsMyFilesFragment fragment, AbsListViewImp listViewImp) {
        super(fragment, listViewImp);
    }

    @Override
    public boolean doDrop(ClipData clipData, int dropPosition) {
        boolean bRet = false;
        FileRecord dstFile = getDstFile(dropPosition);
        if (dstFile != null) {
            if (!UiUtils.canExecuteCloud(mFragment.getActivity(), mFragment.getFragmentManager())) {
                return false;
            }
            bRet = super.doDrop(clipData, dropPosition);
        }
        return bRet;
    }

    @Override
    public void doDrag(View view, ArrayList<FileRecord> selectedFiles, FileRecord pressedFile) {
        if (!UiUtils.canExecuteCloud(mFragment.getActivity(), mFragment.getFragmentManager())) {
            return;
        }
        super.doDrag(view, selectedFiles, pressedFile);
    }

    @Override
    protected boolean handleActionDragLocation(View view, DragEvent event, AbsListView listView, int position, int y) {
        Log.a(this, "ACTION_DRAG_LOCATION");
        FileRecord dstFile = getDstFile(position);
        if (dstFile != null) {
            mNoDrop = (!UiUtils.canExecuteCloud(mFragment.getActivity(), mFragment.getFragmentManager()))
                    || (!DragAndDropMgr.canDrop(mContext, event.getClipDescription()));
            mNeedChangePointer = true;
        }
        updateMousePointerIcon(event);
        return true;
    }
}
